package cn.zyjblogs.starter.sms.config;


import cn.zyjblogs.starter.sms.common.SmsEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhuyijun
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@ConfigurationProperties(prefix = "sms")
public class SmsProperties {

    private AliyunSmsProperties aliyun;
    private TencentSmsProperties tencent;


    @Data
    public static class AliyunSmsProperties {
        private Boolean enable = false;
        private String accessKey;
        //秘钥
        private String accessSecret;
        //ip地址
        private String endpoint;
        //地区
        private String region;
        //模板编号
        private String templateCode;
        /**
         * 批量发送最数量
         */
        private Integer maxSize;

    }

    @Data
    public static class TencentSmsProperties {
        private Boolean enable = false;
        private String accessKey;
        //秘钥
        private String accessSecret;
        //ip地址
        private String endpoint;
        //地区
        private String region;
        //模板编号
        private String templateCode;
        private String sign;
        private String appId;
        private String senderId;
        /**
         * 批量发送最数量
         */
        private Integer maxSize;
    }

    /**
     * 获取已经启用短信服务运营商
     * @return 返回可用运营商枚举名称
     */
    public List<SmsEnum> getAvailableSms(){
        List<SmsEnum> typeNames = new ArrayList<>();
        SmsProperties.AliyunSmsProperties aliyun = getAliyun();
        if (aliyun!= null && Boolean.TRUE.equals(aliyun.getEnable())){
            typeNames.add(SmsEnum.ALI_SMS);
        }
        SmsProperties.TencentSmsProperties tencent = getTencent();
        if (tencent!= null && Boolean.TRUE.equals(tencent.getEnable())){
            typeNames.add(SmsEnum.TEN_SMS);
        }
        return typeNames;
    }
}
